<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>综合管理平台</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <link rel="shortcut icon" href="/static/vue/img/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" href="/static/vue/css/bootstrap.min.css">
    <link rel="stylesheet" href="/static/vue/css/font-awesome.min.css">
    <link rel="stylesheet" href="/static/vue/css/style.css">
    <link rel="stylesheet" href="/static/vue/css/login.css">
    <link rel="stylesheet" href="/static/vue/css/main.css">
    <link rel="stylesheet" href="/static/vue/css/iview.css">
    <link rel="stylesheet" href="/static/cms/layui/css/layui.css">
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
</head>


<body class="fixed-sidebar full-height-layout gray-bg" style="overflow:hidden">
<div id="mainApp" v-cloak>

        <!--左侧导航开始-->
        <nav class="navbar-default navbar-static-side" role="navigation">
            <div class="nav-close"><i class="fa fa-times-circle"></i>
            </div>
            <div class="sidebar-collapse">
                <ul class="nav" id="side-menu">
                    <li class="nav-header">
                        <div class="dropdown profile-element"
                             style="text-align: center;font-size: 18px;font-weight: 600;color: white;">
                            综合管理平台
                        </div>
                        <div class="logo-element">大平台
                        </div>
                    </li>
                    <menu-item :item="item" v-for="item in menuList"></menu-item>
                </ul>
            </div>
        </nav>
        <!--左侧导航结束-->
    <!--右侧部分开始-->
    <div id="page-wrapper" class="gray-bg dashbard-1">
        <div class="border-bottom">
            <nav class="navbar navbar-static-top" role="navigation" style="margin-bottom: 0">
                <div class="navbar-header"><a class="navbar-minimalize minimalize-styl-2 btn btn-primary " href="#"><i
                        class="fa fa-bars"></i> </a>
                    <form role="search" class="navbar-form-custom" method="post" action="#">
                        <div class="form-group">
                            <input type="text" placeholder="请输入您需要查找的内容 …" class="form-control" name="top-search"
                                   id="top-search">
                        </div>
                    </form>
                </div>
                <ul class="nav navbar-top-links navbar-right">
                    <li class="dropdown">
                        <a href="javascript:;" @click="toggleFullScreen"><i class="fa fa-arrows-alt"></i> &nbsp;全屏</a>
                    </li>
                    <li><a href="javascript:;" @click="updatePassword"><i class="fa fa-lock"></i> &nbsp;修改密码</a></li>
                    <!--<li class="dropdown hidden-xs">
                        <a class="right-sidebar-toggle" aria-expanded="false">
                            <i class="fa fa-tasks"></i> 主题
                        </a>
                    </li>-->
                    <li><a @click="logout"><i class="fa fa fa-sign-out"></i>退出</a></li>
                </ul>
            </nav>
        </div>
        <div class="content-tabs">
            <button class="roll-nav roll-left J_tabLeft"><i class="fa fa-backward"></i>
            </button>
            <nav class="page-tabs J_menuTabs">
                <div class="page-tabs-content">
                    <a href="javascript:;" class="active J_menuTab" data-id="main">首页</a>
                </div>
            </nav>
            <button class="roll-nav roll-right J_tabRight"><i class="fa fa-forward"></i>
            </button>
            <div class="btn-group roll-nav roll-right">
                <button class="dropdown J_tabClose" data-toggle="dropdown">关闭操作<span class="caret"></span>

                </button>
                <ul role="menu" class="dropdown-menu dropdown-menu-right">
                    <li class="J_tabShowActive"><a>定位当前选项卡</a></li>
                    <li class="divider"></li>
                    <li class="J_tabCloseAll"><a>关闭全部选项卡</a></li>
                    <li class="J_tabCloseOther"><a>关闭其他选项卡</a>
                    </li>
                </ul>
            </div>
            <a class="roll-nav roll-right J_tabRefresh"><i class="fa fa-refresh"></i> &nbsp;刷新</a>
        </div>
        <div class="J_mainContent" id="content-main">
            <iframe class="J_iframe" name="iframe0" width="100%" height="100%" src="main_default.html" frameborder="0"
                    data-id="main" seamless></iframe>
        </div>
        <div class="footer">
            <div class="pull-right">&copy; 2017-2017 <a href="#" target="_blank">综合管理平台</a>
            </div>
        </div>
    </div>
    <!--右侧部分结束-->

        <!--右侧部分开始-->
        <!--右侧边栏结束-->
        <!-- 修改密码 -->
        <div id="passwordLayer" style="display: none;">
            <form class="form-horizontal" style="width: 350px;">
                <div class="form-group">
                    <div class="form-group">
                        <div class="col-sm-2 control-label">账号</div>
                        <span class="label label-success" style="vertical-align: bottom;">{{user.username}}</span>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">原密码</div>
                        <div class="col-sm-10">
                            <i-input type="password"  v-model="password" placeholder="原密码"/>
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-sm-2 control-label">新密码</div>
                        <div class="col-sm-10">
                            <i-input  v-model="newPassword" placeholder="新密码"/>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</body>

<body class="hold-transition skin-blue sidebar-mini">

<script src="/static/vue/libs/jquery.min.js"></script>
<script src="/static/vue/libs/vue.min.js"></script>

<script src="/static/vue/libs/iview.min.js"></script>
<script src="/static/vue/libs/bootstrap.min.js"></script>

<script src="/static/vue/plugins/layer/layer.js"></script>
<script src="/static/vue/libs/contabs.js"></script>
<script src="/static/vue/libs/content.js"></script>
<script src="/static/vue/libs/hplus.js"></script>
<script src="/static/vue/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="/static/vue/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="/static/vue/js/common.js"></script>
<script src="/static/cms/layui/layui.js"></script>
<script>

    // 顶部左侧导航控制开关
    $('#toggle').click(function () {
        var sideWidth = $('#larry-side').width();
        var bodyW = $('#content-main').width();
        if (sideWidth === 200) {
            bodyW += 203;
            $('#content-main').animate({
                left: '0',
                width: bodyW
            });
            $('#footer').animate({
                left: '0',
                width: bodyW
            });
            $('#larry-side').animate({
                width: '0'
            });
        } else {
            bodyW -= 203;
            $('#content-main').animate({
                left: '203px',
                width: bodyW
            });
            $('#footer').animate({
                left: '203px',
                width: bodyW
            });
            $('#larry-side').animate({
                width: '200px'
            });
        }
    });

    //注意：导航 依赖 element 模块，否则无法进行功能性操作
    layui.use('element', function(){
        var element = layui.element;

        //…
    });

    //生成菜单
    var menuItem = Vue.extend({
        name: 'menu-item',
        props: {item: {}},
        template: [
            '<li>',
            '<a v-if="item.type === 0" href="#">',
            /*'<i v-if="item.icon != null" :class="item.icon"></i>',*/
            '<span class="nav-label">{{item.name}}</span>',
            '<span class="fa arrow"></span>',
            '</a>',
            '<ul v-if="item.type === 0" class="nav nav-second-level">',
            '<menu-item :item="item" v-for="item in item.children"></menu-item>',
            '</ul>',
            '<a v-if="item.type === 1" class="J_menuItem" :href="item.url"><!--<i :class="item.icon"></i>-->{{item.name}}</a>',
            '</li>'
        ].join('')
    });
    //注册菜单组件
    Vue.component('menuItem', menuItem);

    var vm = new Vue({
        el: '#mainApp',
        data: {
            password: '',
            newPassword: '',
            menuList: {},
            user: {},
            queryMessage:''
        },
        methods: {
            getMenuList: function (event) {
                $.getJSON("/admin/permission/user/list.json?_" + $.now(), function (r) {
                    //alert("success");
                    if(r.permissionList == null){
                        /*layer.open({
                            type: 1,
                            skin: 'layui-layer-molv',
                            title: "系统异常，请重新登录！",
                            area: ['350px', '300px'],
                            shadeClose: false,
                            content: jQuery("#passwordLayer"),
                            btn: ['修改', '取消'],
                            btn1: function (index) {
                                var data = "password=" + vm.password + "&newPassword=" + vm.newPassword;
                                $.ajax({
                                    type: "POST",
                                    url: "/admin/tologin",
                                    data: data,
                                    dataType: "json",
                                    success: function (result) {
                                        if (result.code == 0) {
                                            layer.close(index);
                                            layer.alert('修改成功', function (index) {
                                                location.reload();
                                            });
                                        } else {
                                            layer.alert(result.msg);
                                        }
                                    }
                                });
                            }
                        });*/
                        confirm('系统异常，请重新登录', function () {
                            dialogLoading(true);
                            setTimeout(function () {
                                toUrl('tologin?_' + $.now());
                            }, 500);
                        });
                    }
                    vm.menuList = r.permissionList;

                });
               // alert("fail");
            },
            getUser: function () {
                $.getJSON("admin/user/info?_" + $.now(), function (r) {
                    vm.user = r.user;
                });
            },
            updatePassword: function () {
                vm.getUser();
                /*layer.open({
                    type: 1,
                    skin: 'layui-layer-molv',
                    title: "修改密码",
                    area: ['350px', '300px'],
                    shadeClose: false,
                    content: jQuery("#passwordLayer"),
                    btn: ['修改', '取消'],
                    btn1: function (index) {
                        var data = "password=" + vm.password + "&newPassword=" + vm.newPassword;
                        $.ajax({
                            type: "POST",
                            url: "admin/user/password",
                            data: data,
                            dataType: "json",
                            success: function (result) {
                                if (result.code == 0) {
                                    layer.close(index);
                                    layer.alert('修改成功', function (index) {
                                        location.reload();
                                    });
                                } else {
                                    layer.alert(result.msg);
                                }
                            }
                        });
                    }
                });*/
            },
            toggleFullScreen: function () {
                if (!document.fullscreenElement && // alternative standard method
                    !document.mozFullScreenElement && !document.webkitFullscreenElement) {// current working methods
                    if (document.documentElement.requestFullscreen) {
                        document.documentElement.requestFullscreen();
                    } else if (document.documentElement.mozRequestFullScreen) {
                        document.documentElement.mozRequestFullScreen();
                    } else if (document.documentElement.webkitRequestFullscreen) {
                        document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
                    }
                } else {
                    if (document.cancelFullScreen) {
                        document.cancelFullScreen();
                    } else if (document.mozCancelFullScreen) {
                        document.mozCancelFullScreen();
                    } else if (document.webkitCancelFullScreen) {
                        document.webkitCancelFullScreen();
                    }
                }
            },
            logout: function () {
                confirm('注：您确定要安全退出本次登录吗？', function () {
                    dialogLoading(true);
                    setTimeout(function () {
                        toUrl('logout?_' + $.now());
                    }, 500);
                });
            },
            queryContent:function (event) {
                alert("hello"+vm.queryMessage);
            }
        },
        created: function () {
            this.getMenuList();
            /*this.love();*/
        },
        updated: function () {
            // MetsiMenu
            $('#side-menu').metisMenu();

            //通过遍历给菜单项加上data-index属性
            $(".J_menuItem").each(function (index) {
                if (!$(this).attr('data-index')) {
                    $(this).attr('data-index', index);
                }
            });

            $('.J_menuItem').on('click', menuItem);

            function menuItem() {
                // 获取标识数据
                var dataUrl = $(this).attr('href'),
                    dataIndex = $(this).data('index'),
                    menuName = $.trim($(this).text()),
                    flag = true;
                if (dataUrl == undefined || $.trim(dataUrl).length == 0) return false;

                // 选项卡菜单已存在
                $('.J_menuTab').each(function () {
                    if ($(this).data('id') == dataUrl) {
                        if (!$(this).hasClass('active')) {
                            $(this).addClass('active').siblings('.J_menuTab').removeClass('active');
                            scrollToTab(this);
                            // 显示tab对应的内容区
                            $('.J_mainContent .J_iframe').each(function () {
                                if ($(this).data('id') == dataUrl) {
                                    $(this).show().siblings('.J_iframe').hide();
                                    return false;
                                }
                            });
                        }
                        flag = false;
                        return false;
                    }
                });

                // 选项卡菜单不存在
                if (flag) {
                    var str = '<a href="javascript:;" class="active J_menuTab" data-id="' + dataUrl + '">' + menuName + ' <i class="fa fa-times-circle"></i></a>';
                    $('.J_menuTab').removeClass('active');

                    // 添加选项卡对应的iframe
                    var str1 = '<iframe class="J_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + dataUrl + '" frameborder="0" data-id="' + dataUrl + '" seamless></iframe>';
                    $('.J_mainContent').find('iframe.J_iframe').hide().parents('.J_mainContent').append(str1);

                    // 显示loading提示
                    var loading = layer.load();

                    $('.J_mainContent iframe:visible').load(function () {
                        //iframe加载完成后隐藏loading提示
                        layer.close(loading);
                    });
                    // 添加选项卡
                    $('.J_menuTabs .page-tabs-content').append(str);
                    scrollToTab($('.J_menuTab.active'));
                }
                return false;
            }

            //滚动到指定选项卡
            function scrollToTab(element) {
                var marginLeftVal = calSumWidth($(element).prevAll()),
                    marginRightVal = calSumWidth($(element).nextAll());
                // 可视区域非tab宽度
                var tabOuterWidth = calSumWidth($(".content-tabs").children().not(".J_menuTabs"));
                //可视区域tab宽度
                var visibleWidth = $(".content-tabs").outerWidth(true) - tabOuterWidth;
                //实际滚动宽度
                var scrollVal = 0;
                if ($(".page-tabs-content").outerWidth() < visibleWidth) {
                    scrollVal = 0;
                } else if (marginRightVal <= (visibleWidth - $(element).outerWidth(true) - $(element).next().outerWidth(true))) {
                    if ((visibleWidth - $(element).next().outerWidth(true)) > marginRightVal) {
                        scrollVal = marginLeftVal;
                        var tabElement = element;
                        while ((scrollVal - $(tabElement).outerWidth()) > ($(".page-tabs-content").outerWidth() - visibleWidth)) {
                            scrollVal -= $(tabElement).prev().outerWidth();
                            tabElement = $(tabElement).prev();
                        }
                    }
                } else if (marginLeftVal > (visibleWidth - $(element).outerWidth(true) - $(element).prev().outerWidth(true))) {
                    scrollVal = marginLeftVal - $(element).prev().outerWidth(true);
                }
                $('.page-tabs-content').animate({
                    marginLeft: 0 - scrollVal + 'px'
                }, "fast");
            }

            //计算元素集合的总宽度
            function calSumWidth(elements) {
                var width = 0;
                $(elements).each(function () {
                    width += $(this).outerWidth(true);
                });
                return width;
            }
        }
    });
</script>
</body>
</html>
